# -*- coding: utf-8 -*-
# @Time    : 2024/11/29 上午9:31
# @Author  : wjx
# @Email   : kanxinxin@163.com
# @File    : home_page.py
# @Software: PyCharm
from appium.webdriver.common.appiumby import AppiumBy as By
from pages.base_page import BasePage


class HomePage(BasePage):
    # 定位器
    upload_locator = (By.ID, 'com.xiachufang:id/iv_home_upload')  # 中间＋号
    collect_locator = (By.XPATH,
                       '(//android.widget.LinearLayout[@resource-id="com.xiachufang:id/icon"])[4]/android.widget.ImageView')  # 收藏按钮
    # 我
    my_locator = (By.XPATH, '(//android.widget.LinearLayout[@resource-id="com.xiachufang:id/icon"])['
                            '5]/android.widget.ImageView')
    # 选择第一个信息
    choose1_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_img").instance(0)')
    choose2_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_img").instance(0)')
    choose3_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_img").instance(2)')
    # 点击收藏按钮
    collect_btn_locator = (By.ID, 'com.xiachufang:id/recipe_bto_nav_bar_collect')
    # 点击返回
    back_locator = (
        By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/img_container").instance(0)')

    def click_upload(self):
        """
        点击首页导航栏中间加号
        :return: None
        """
        self.find_element(self.upload_locator).click()

    def click_collect(self):
        """
        点击首页导航栏收藏按钮
        :return: None
        """
        self.find_element(self.collect_locator).click()

    def click_my(self):
        """
        点击我
        :return:None
        """
        self.find_element(self.my_locator).click()

    def click_first(self):
        """
        点击第一个
        :return:None
        """
        self.find_element(self.choose1_locator).click()

    def click_second(self):
        """
        点击第二个
        :return:None
        """
        self.find_element(self.choose2_locator).click()

    def click_third(self):
        """
        点击第三个
        :return:None
        """
        self.find_element(self.choose3_locator).click()

    def click_collect_btn(self):
        """
        点击收藏按钮进行收藏操作
        :return: None
        """
        self.find_element(self.collect_btn_locator).click()

    def click_back(self):
        """
        点击返回
        :return:None
        """
        self.find_element(self.back_locator).click()
